#include "thread.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>


void func(void * nom){

  if ((int)nom == 1){
    sleep(0.1);
  }

}


int main(){
  struct timeval depart, fin;
  struct timezone tz;
  long duree=0;
  void *retval = malloc(sizeof(int));
  int i;
  int arg = 100;

  for(i=0;i<arg;i++){
    thread_t thread[i];
    thread_create(&thread[i],(void * (*) (void *))func,(void *)1);
  }
  
  gettimeofday(&depart, &tz);
  {
    thread_t threadTest;
    thread_create(&threadTest,(void * (*) (void *))func,(void *)0);
    thread_join(threadTest,&retval);
    
  }
  gettimeofday(&fin, &tz);

  /*
  for(i=0;i<arg;i++){
    thread_join(&thread[i],&retval);
  }
  */
  
  duree=(fin.tv_sec-depart.tv_sec) * 1000000L + (fin.tv_usec-depart.tv_usec);  
  printf("Durée: %ld microsecondes\n", duree);
  
  return 0;
}
